package com.VolunteerPlatform.Service.VolunteerService.Impl;

import com.VolunteerPlatform.Dao.VolunteerRecordDao;
import com.VolunteerPlatform.Entity.VolunteerRecord;
import com.VolunteerPlatform.Service.VolunteerService.VolunteerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by DoveXL on 2018/12/18.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class VolunteerRecordServiceImpl implements VolunteerRecordService{
    @Autowired
    private VolunteerRecordDao volunteerRecordDao;

    public int insertVolunteerRecord(String IDCardNumber,String Name,String TeamName, String Date, String StartTime,String EndTime,int TeamNumber,double Duration,String AdminID)
    {
        return volunteerRecordDao.insertVolunteerRecord(IDCardNumber, Name, TeamName, Date, StartTime, EndTime, TeamNumber, Duration, AdminID);
    }

    public int deleteVolunteerRecord(String IDCardNumber,String TeamName, String Date)
    {
        return volunteerRecordDao.deleteVolunteerRecord(IDCardNumber, TeamName, Date);
    }


    public int updateVolunteerRecord(String IDCardNumber,String Name,String TeamName, String NewTeamName,String Date, String NewDate,String StartTime,String EndTime,int TeamNumber,double Duration,String AdminID)
    {


        return volunteerRecordDao.updateVolunteerRecord(IDCardNumber, Name, TeamName, NewTeamName,Date,NewDate, StartTime, EndTime, TeamNumber, Duration, AdminID);
    }

    public List<VolunteerRecord> getAllVolunteerRecord(String IDCardNumber, String Name, String TeamName, String StartDate, String EndDate, String Unit,String AdminID, int Page, int PageList){

        String IDCardNumberLike = "";
        String NameLike = "";
        String TeamNameLike = "";
        String UnitLike = "";
        if(IDCardNumber==null)
        {
            IDCardNumberLike=null;
        }else
        {
            IDCardNumberLike = "%"+IDCardNumber+"%";
        }

        if(Name==null)
        {
            NameLike=null;
        }else
        {
            NameLike = "%"+Name+"%";
        }
        if(TeamName==null)
        {
            TeamNameLike=null;
        }else
        {
            TeamNameLike = "%"+TeamName+"%";
        }
        if(Unit==null)
        {
            UnitLike=null;
        }else
        {
            UnitLike = "%"+Unit+"%";
        }

        return volunteerRecordDao.getAllVolunteerRecord(IDCardNumberLike,NameLike,TeamNameLike,StartDate,EndDate,UnitLike,AdminID,Page,PageList);
    }



}
